<?php
namespace app\index\controller;
use think\Controller;
use think\Db;


class Index extends Controller
{
    public function index()
    {
        $this->redirect('index/index/login');
    }

    public function login(){
        return $this->fetch();
    }

    public function userLogin(){
        $post = input("post.");
        if($user = Db::name('user')->where($post)->find()){
            $userInfo = [
                "nickname"=>$user["nickname"],
                "username"=>$user["username"],
                "role"=>$user["role"],
                "type"=>$user["type"]
            ];
            $token = encryptCookie(json_encode($userInfo), config('app.key'));
            setcookie('token', $token, time() + 3600*60*24*3, '/');
            return json(["code"=>200,"msg"=>"登录成功"]);
        }
        return json(["code"=>-1,"msg"=>"账号或密码错误"]);
    }
}